//axios模块
//引入axios
import store from '@/store'
import axios from 'axios'

//封装公共地址+超时时间
const instance = axios.create({
    baseURL: 'http://sell.h5.itsource.cn:8087',
    timeout: 10000,
})

//封装请求拦截器
instance.interceptors.request.use(
    config => {
        const token = store.getters.token
        token && (config.headers.authorization = token)
            //config.headers.authorization = token
            // console.log('token :>> ', token); //有token
        return config
    },
    err => {
        return Promise.reject(err)
    }
)

//封装响应拦截器
instance.interceptors.response.use(
        response => {
            return response
        },
        err => {
            return Promise.reject(err)
        }
    )
    //导出封装好的实例
export default instance